﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace TranslatorClient
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            List<string> sourceTypesList = new List<string>();
            sourceTypesList.Add("Hex");
            this.comboBoxSource.ItemsSource = sourceTypesList;
            this.comboBoxSource.SelectedIndex = 0;

            List<string> endienTypesList = new List<string>();
            endienTypesList.Add("Little Endian");
            endienTypesList.Add("Big Endian");
            this.comboBoxEndian.ItemsSource = endienTypesList;
            this.comboBoxEndian.SelectedIndex = 0;
            this.comboBoxEndian.IsEnabled = false;

            this.comboBoxTarget.ItemsSource = App.dtManager._AvailableTypeList;
            this.comboBoxTarget.SelectedIndex = 0;
        }

        private void MenuItem_Click_Settings(object sender, RoutedEventArgs e)
        {
            MessageBox.Show("Option Dialog");
        }

        private void MenuItem_Click_About(object sender, RoutedEventArgs e)
        {
            MessageBox.Show("About... Dialog");
        }

        private void ShowErrorMessage(Translator.Translator.ErrorCode eCode)
        {
            switch (eCode)
            {
                case Translator.Translator.ErrorCode.NoError:
                    this.labelStatus.Content = "Success.";
                    break;
                case Translator.Translator.ErrorCode.BytesLenthNotEnough:
                    this.labelStatus.Content = "Input is not long enough. Some bytes may haven't been translated.";
                    break;
                case Translator.Translator.ErrorCode.UnsupportedType:
                    this.labelStatus.Content = "Unsupported target type.";
                    break;
            }
        }
        private void btnTranslate_Click(object sender, RoutedEventArgs e)
        {
            this.textTarget.Text = Translator.Translator.Translate(this.textSource.Text,
                comboBoxTarget.Text);
            ShowErrorMessage(Translator.Translator.eLastError);
        }
    }
}
